package com.rong.action;

import java.util.List;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.rong.DAO.ZynCarDAO;
import com.rong.DAO.ZynCompanyDAO;
import com.rong.ORM.ZynCar;
import com.rong.ORM.ZynCompany;
import com.rong.ORM.ZynUser;
import com.rong.ORM.ZynUserRight;

public class ComAction extends ActionSupport {
	ZynCompany com=new ZynCompany();
	ZynCompanyDAO comDao=new ZynCompanyDAO();
	private List<ZynCompany> list;
	private String saveFlag="";
	private int id=-1; // the car id in database.
	
	// query 
	private String query_comname="";
	private String comPro="" ;
	private String query_distric="" ;
	private int query_blongto=-1 ;
		
	private int rowsPerPage =25;// 每页显示几条
	private int page = 1; // 默认当前页
	private int totalPage;// 总共多少页
	private int planNum;// 总过多少条
	
	// query
	
	/**
	 * @return the saveFlag
	 */
	public String getSaveFlag() {
		return saveFlag;
	}
	/**
	 * @param saveFlag the saveFlag to set
	 */
	public void setSaveFlag(String saveFlag) {
		this.saveFlag = saveFlag;
	}
	/**
	 * @return the com
	 */
	public ZynCompany getCom() {
		return com;
	}
	/**
	 * @param com the com to set
	 */
	public void setCom(ZynCompany com) {
		this.com = com;
	}
	/**
	 * @return the list
	 */
	public List<ZynCompany> getList() {
		return list;
	}
	/**
	 * @param list the list to set
	 */
	public void setList(List<ZynCompany> list) {
		this.list = list;
	}
	
	
	/**
	 * @return the id
	 */
	public int getId() {
		return id;
	}
	/**
	 * @param id the id to set
	 */
	public void setId(int id) {
		this.id = id;
	}
	
	/**
	 * @return the rowsPerPage
	 */
	public int getRowsPerPage() {
		return rowsPerPage;
	}
	/**
	 * @param rowsPerPage the rowsPerPage to set
	 */
	public void setRowsPerPage(int rowsPerPage) {
		this.rowsPerPage = rowsPerPage;
	}
	/**
	 * @return the page
	 */
	public int getPage() {
		return page;
	}
	/**
	 * @param page the page to set
	 */
	public void setPage(int page) {
		this.page = page;
	}
	/**
	 * @return the totalPage
	 */
	public int getTotalPage() {
		return totalPage;
	}
	/**
	 * @param totalPage the totalPage to set
	 */
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	/**
	 * @return the planNum
	 */
	public int getPlanNum() {
		return planNum;
	}
	/**
	 * @param planNum the planNum to set
	 */
	public void setPlanNum(int planNum) {
		this.planNum = planNum;
	}
	/**
	 * @return the query_comname
	 */
	public String getQuery_comname() {
		return query_comname;
	}
	/**
	 * @param query_comname the query_comname to set
	 */
	public void setQuery_comname(String query_comname) {
		this.query_comname = query_comname;
	}
	
	/**
	 * @return the comPro
	 */
	public String getComPro() {
		return comPro;
	}
	/**
	 * @param comPro the comPro to set
	 */
	public void setComPro(String comPro) {
		this.comPro = comPro;
	}
	/**
	 * @return the query_distric
	 */
	public String getQuery_distric() {
		return query_distric;
	}
	/**
	 * @param query_distric the query_distric to set
	 */
	public void setQuery_distric(String query_distric) {
		this.query_distric = query_distric;
	}
	
	
	
	/**
	 * @return the query_blongto
	 */
	public int getQuery_blongto() {
		return query_blongto;
	}
	/**
	 * @param query_blongto the query_blongto to set
	 */
	public void setQuery_blongto(int query_blongto) {
		this.query_blongto = query_blongto;
	}
	@Override
    public String execute() throws Exception {
        this.setSaveFlag("");
		comDao.save(this.com);        //保存注册的com对象
		 this.setSaveFlag("保存成功..");
        return SUCCESS;
    }
	 public String findall() throws Exception {
	        
		 this.setList(comDao.findAll());        //保存注册的user对象
	        return "success_list";
	    }
	 
	 public String toGetComList() throws Exception {
		  
		this.setList(comDao.findComQueryByPage(page, rowsPerPage,this.getQuery_comname(),this.getQuery_blongto(),this.getQuery_distric(),this.getComPro()));       
        this.setPlanNum(comDao.comTatolRows(this.getQuery_comname(),this.getQuery_blongto(),this.getQuery_distric(),this.getComPro()).size());
        this.setTotalPage(this.getPlanNum() % this.getRowsPerPage()==0?this.getPlanNum()/this.getRowsPerPage():this.getPlanNum()/this.getRowsPerPage()+1);     
	        return "success_list";
	    }
	 
	 
	 public String findbyid() throws Exception {
	        
		this.setCom(comDao.findById(this.getId()));// find the com by id			
	        return "s_find_one";
	       
	    }
	 public String edit() throws Exception {
	        
			comDao.merge(this.getCom());// edit the com by id			
		    return "s_edit_one";
		    }
	 public String delete() throws Exception {
	        
			comDao.delete(comDao.findById(this.getId()));// delete the com by id			
		    return "s_delete_one";
		    }
}
